﻿using System;
using System.Windows;
using System.Windows.Navigation;

using Microsoft.Phone.Controls;

namespace Microsoft.Phone
{
    /// <summary>
    /// <see cref="Application">Application</see> level utility methods set.
    /// </summary>
    public static class ApplicationUtility
    {
        /// <summary>
        /// Removes <see cref="JournalEntry">JournalEntries</see> from navigation journal until <paramref name="condition"/> is not true.
        /// </summary>
        /// <param name="condition">Condition that determines whether deleting process should be stopped or not.</param>
        public static void RemoveBackStackEntriesWhile(Func<JournalEntry, bool> condition)
        {
            var frame = Application.Current.RootVisual as PhoneApplicationFrame;

            frame.RemoveBackStackEntriesWhile(condition);
        }

        /// <summary>
        /// Removes <see cref="JournalEntry">JournalEntries</see> from navigation journal leaving predefined <paramref name="count"/>.
        /// </summary>
        /// <param name="count">Number of entries to leave.</param>
        public static void RemoveBackStackEntries(int count = 0)
        {
            var frame = Application.Current.RootVisual as PhoneApplicationFrame;

            frame.RemoveBackStackEntries(count);
        }
    }
}
